local spellID = C_AssistedCombat.GetNextCastSpell()
-- dummy GCD
local GCD_ID = 61304
-- Rotational Core
local TP_ID              = 100780  -- Tiger Palm
local RSK_ID             = 107428  -- Rising Sun Kick
local BOK_ID             = 100784  -- Blackout Kick
local FOF_ID             = 113656  -- Fists of Fury
local SCK_ID             = 101546  -- Spinning Crane Kick

-- Talent Abilities
local WDP_ID             = 152175  -- Whirling Dragon Punch
local SW_ID              = 1217413 -- Surging Winds
local RWK_ID             = 1250566 -- Rushing Wind Kick
local SOTW_ID            = 392983  -- Strike of the Windlord

-- Utility  
local TOD_ID             = 322109  -- Touch of Death
local CJL_ID             = 117952  -- Crackling Jade Lightning
local ZS_ID				 = 1272696 -- Zenith Stomp 

local OS_ID				 = 1249832 -- Obsidian Spiral (causes BoK to generate chi during zenith)

local chi = UnitPower("player", Enum.PowerType.Chi)
--currentEnergy is estimated of of ability use and haste value
--haste is estimated off of global cooldown duration. It is accurate up to 33% if you hav more than 33% haste due to a buff or stats it will cap out at 33% causing current energy to fall short of expected.

--Priorities
--1.) TOD ignored
--Utilize ProcViewer as it is more reliable

--1b.) todo if conduit maintain heart of the jade serpent
--1c.) if conduit then conduit
--1d.) xuen




--2.) WDP
if (IsPlayerSpell(WDP_ID) and not C_Spell.GetSpellCooldown(WDP_ID).isActive and C_Spell.IsSpellUsable(WDP_ID)) or spellID == WDP_ID then return WDP_ID end

--2.5) WDP
if C_Spell.GetSpellCooldown(WDP_ID).isEnabled and C_Spell.GetSpellCooldown(FOF_ID).isActive and 
C_Spell.GetSpellCooldown(RSK_ID).isActive and
--C_Spell.IsSpellUsable(WDP_ID) and 
not C_Spell.GetSpellCooldown(WDP_ID).isActive
 then
spellID = WDP_ID
return WDP_ID
end

--3.) TP to not cap energy
if (not ZenithActiveTracker or (ZenithActiveTracker and not IsPlayerSpell(OS_ID))) and chi < 4 and not bok_proc_active and (spellID == TP_ID or currentEnergy > 85) and LastComboStrikeSpellID ~= TP_ID then 
    return TP_ID end

--4.) SOTW
if (IsPlayerSpell(SOTW_ID) and not C_Spell.GetSpellCooldown(SOTW_ID).isActive and C_Spell.IsSpellUsable(SOTW_ID)) or spellID == SOTW_ID then return SOTW_ID end

--5.) FOF
if not C_Spell.GetSpellCooldown(FOF_ID).isActive and C_Spell.IsSpellUsable(FOF_ID) then return FOF_ID end
if (not C_Spell.GetSpellCooldown(FOF_ID).timeUntilEndOfStartRecovery and C_Spell.IsSpellUsable(FOF_ID)) or spellID == FOF_ID then return FOF_ID end

if spellID == FOF_ID and (chi > 2 or ZenithActiveTracker and chi > 1) then return FOF_ID end


--6.) RWK
if (chi > 0 and ZenithActiveTracker and rwk_proc_active) or (chi > 1 and rwk_proc_active) or spellID==RWK_ID then return RWK_ID end

--7.) SCK - to not waste procs
if  not ZenithActiveTracker and docj_proc_active and docj_proc_timer < 4 and not bok_proc_active  and LastComboStrikeSpellID ~= SCK_ID then return SCK_ID end

--8.) RSK -- for some reason blizz reccomends RSK when you don't have enough chi to use it. We verify chi.
if (not C_Spell.GetSpellCooldown(RSK_ID).isActive and C_Spell.IsSpellUsable(RSK_ID)) or (chi>0 and ZenithActiveTracker and spellID==RSK_ID) or (chi>1 and spellID==RSK_ID) then return RSK_ID end

if spellID == RSK_ID and  (chi > 1 or ZenithActiveTracker and chi > 0) then return RSK_ID end

--8.25) Zenith Stomp if it is usable and we are in Zenith (currently not on combo strikes, but expecting that to be a bug
if C_Spell.IsSpellUsable(ZS_ID) and ZenithActiveTracker  then
return ZS_ID
end


--8.5) BOK to build chi during zenith
 if ZenithActiveTracker and IsPlayerSpell(OS_ID) and LastComboStrikeSpellID ~= BOK_ID then return BOK_ID end

--9.) TP to use high ability
if not (C_Spell.GetSpellCooldown(RSK_ID).isActive or (IsPlayerSpell(RWK_ID) and not C_Spell.GetSpellCooldown(RWK_ID).isActive) or not C_Spell.GetSpellCooldown(FOF_ID).isActive or (IsPlayerSpell(SOTW_ID) and not C_Spell.GetSpellCooldown(SOTW_ID).isActive)) and chi < 3 and LastComboStrikeSpellID ~= TP_ID then
    return TP_ID
end


--10.) BOK with Proc or Zenith
if (ZenithActiveTracker or bok_proc_active) and LastComboStrikeSpellID ~= BOK_ID then return BOK_ID end


--11.) Zenith SCK
if ZenithActiveTracker and chi > 3 then return SCK_ID end


--12.) SCK with docj
if docj_proc_active and LastComboStrikeSpellID ~= SCK_ID then return SCK_ID end


--13.) Slicing Winds
if IsPlayerSpell(SW_ID) and not C_Spell.GetSpellCooldown(SW_ID).isActive and C_Spell.IsSpellUsable(SW_ID) then return SW_ID end


--14.) BOK
if (chi > 1 or (chi == 1 and LastComboStrikeSpellID == TP_ID)) and LastComboStrikeSpellID ~= BOK_ID then return BOK_ID end

--14.5.) SCK --once I get a an enemy count libray will be enemies greater than 2
if spellID == SCK_ID then return SCK_ID end

--15.) TP 
if LastComboStrikeSpellID ~= TP_ID then return TP_ID end

--16.) CJL last resort
if LastComboStrikeSpellID == TP_ID then return CJL_ID end

--Use Default Spell
return spellID